/*
 * Created by JFormDesigner on Tue Sep 12 00:18:16 PST 2023
 */

package org.vikingclient.gui.anthentication;

import lombok.Getter;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

/**
 * @author chengchen
 */
@Getter
public class ClientLoginForm extends JFrame {
    public ClientLoginForm() {
        initComponents();
    }

    private void loginClientUser(ActionEvent e) {
        // TODO add your code here
        if(textFieldUsername.getText().isEmpty() || new String(passwordField.getPassword()).isEmpty()){
            JOptionPane.showMessageDialog(this, "用户名或密码不能为空！", "提示", JOptionPane.WARNING_MESSAGE);
            return;
        }

        if(1 == 0){

        }else {
            /** 3.如果登陆失败,则在窗体显示 */
            JOptionPane.showMessageDialog(
                    this,
                    "登陆失败，请检查用户名和密码！",
                    "警告！！！",
                    JOptionPane.WARNING_MESSAGE
            );
        }
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        // Generated using JFormDesigner Educational license - chan (CHEN CHENG)
        labelUsername = new JLabel();
        labelPassword = new JLabel();
        textFieldUsername = new JTextField();
        buttonLogin = new JButton();
        passwordField = new JPasswordField();
        checkBoxRememberName = new JCheckBox();
        checkBoxRememberPWD = new JCheckBox();

        //======== this ========
        setTitle("\u6355\u9cb8\u8005\u5ba2\u6237\u7aef");
        setResizable(false);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- labelUsername ----
        labelUsername.setText("\u7528\u6237\u540d\uff1a");
        contentPane.add(labelUsername);
        labelUsername.setBounds(50, 35, 65, 20);

        //---- labelPassword ----
        labelPassword.setText("\u5bc6    \u7801\uff1a");
        contentPane.add(labelPassword);
        labelPassword.setBounds(50, 80, 65, 20);
        contentPane.add(textFieldUsername);
        textFieldUsername.setBounds(115, 30, 150, 35);

        //---- buttonLogin ----
        buttonLogin.setText("\u767b   \u5f55");
        buttonLogin.addActionListener(e -> loginClientUser(e));
        contentPane.add(buttonLogin);
        buttonLogin.setBounds(65, 160, 190, buttonLogin.getPreferredSize().height);
        contentPane.add(passwordField);
        passwordField.setBounds(115, 75, 150, 35);

        //---- checkBoxRememberName ----
        checkBoxRememberName.setText("\u8bb0\u4f4f\u7528\u6237\u540d");
        contentPane.add(checkBoxRememberName);
        checkBoxRememberName.setBounds(new Rectangle(new Point(50, 120), checkBoxRememberName.getPreferredSize()));

        //---- checkBoxRememberPWD ----
        checkBoxRememberPWD.setText("\u8bb0\u4f4f\u5bc6\u7801");
        contentPane.add(checkBoxRememberPWD);
        checkBoxRememberPWD.setBounds(new Rectangle(new Point(185, 120), checkBoxRememberPWD.getPreferredSize()));

        contentPane.setPreferredSize(new Dimension(325, 260));
        setSize(325, 260);
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Educational license - chan (CHEN CHENG)
    private JLabel labelUsername;
    private JLabel labelPassword;
    private JTextField textFieldUsername;
    private JButton buttonLogin;
    private JPasswordField passwordField;
    private JCheckBox checkBoxRememberName;
    private JCheckBox checkBoxRememberPWD;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
